import { ESGeoExtrudedPolygon, ESJEditingMode } from "earthsdk3";
import { ElMessage } from "element-plus";
import { SceneObjectKey, UniteChanged, reactJsonWithUndefined } from "earthsdk3";

/**
 * 测试 ModelSer使用的挤压多边形体
 */
export class ESGeoExtrudedPolygonUFMS extends ESGeoExtrudedPolygon {
    static createDefaultProps = () => ({
        ...ESGeoExtrudedPolygon.createDefaultProps(),
        operation: undefined as '2' | '1' | undefined,
        bottom: undefined as number | undefined,
        ceilling: undefined as number | undefined,
        srcGeom: reactJsonWithUndefined<{ [xx: string]: any }>(undefined),
        absoluteCeilling: undefined as boolean | undefined,
        absoluteBottom: undefined as boolean | undefined,
        collision: false
    });
    static override readonly type: string = this.register('ESGeoExtrudedPolygonUFMS', this, { chsName: 'ModelSer使用的地理多边形体', tags: ['ESObjects', '_ES_Impl_Cesium', '_ES_Impl_UE'], description: "地理多边形体" });

    static operations = [["2", "压平"], ["1", "裁剪"]] as [name: string, value: string][]
    static override supportEditingModes: string[] = [
        ESJEditingMode.Translation,
        ...ESGeoExtrudedPolygon.supportEditingModes
    ];

    override updateEditing() {
        const mode = [
            ESJEditingMode.CircularAppend,
            ESJEditingMode.Translation,
            ESJEditingMode.CircularInsert
        ]
        if (this.points && this.points.length > 2) {
            mode.reverse();
        }
        this.activeViewer?.startEditing(this, mode, { callSource: 'inner' });
    }
    constructor(id?: SceneObjectKey) {
        super(id);

        {
            let message: any
            const updata = () => {
                if (this.editing) {
                    message = ElMessage({
                        message: '1. 双击鼠标左键或点击ESC键退出编辑2. 点击空格键进行编辑方式的切换',
                        duration: 0,
                        plain: true,
                    })
                } else {
                    message && message.close()
                }
            }
            this.dispose(this.editingChanged.disposableOn(updata))
            this.dispose(() => message && message.close())
        }
    }
}


export interface ESGeoExtrudedPolygonUFMS extends UniteChanged<ReturnType<typeof ESGeoExtrudedPolygonUFMS.createDefaultProps>> { }
